Gin+Gorm v2+Github Action的实践
Github Action
- GitHub Actions
- Github Actions教程
- GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker
- Building Docker containers with GitHub Actions
- 🚀 GitHub Action for release your Go projects as fast and easily as possible
GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.
下面,我们就实践一下:
- 通过Github Action实现对Go项目的release
- 通过Github Action对Go项目进行打包并生成Docker镜像
通过Github Action实现对Go项目的release
主要参考:🚀 GitHub Action for release your Go projects as fast and easily as possible
后续补
通过Github Action对Go项目进行打包并生成Docker镜像
后续补
Gin+Gorm v2的实践
仓库地址:https://github.com/qingbo1011/gin-gorm2.0
就写一个简单的登录注册来实践一下Gin+Gorm v2吧。
首先在conf/
下创建config.ini
:
1 | [service] |
HttpPort的含义就不用多说了,指定gin的端口为8080。
主要说一下Msyql相关配置:
MysqlHost = 127.0.0.1
:MySQL主机HostMysqlPort = 3308
:MySQL端口MysqlUser = root
:MySQL用户名MysqlPassword = 123456
:MySQL密码MysqlDataBase = gorm2
:MySQL数据库名MysqlCharset = utf8mb4
:MySQL数据库编码MysqlLogMode = 4
:Gorm2.0的日志级别(1,2,3,4分别代表Silent
、Error
、Warn
、Info
)MysqlDefaultStringSize = 256
:string类型字段的默认长度MysqlDisableDatetimePrecision = true
:禁用datetime精度,MySQL5.6之前的数据库不支持MysqlDontSupportRenameIndex = true
: 重命名索引时采用删除并新建的方式,MySQL5.7之前的数据库和MariaDB不支持重命名索引MysqlDontSupportRenameColumn = true
:用change重命名列,MySQL8之前的数据库和MariaDB不支持重命名列MysqlSkipInitializeWithVersion = false
:根据当前MySQL版本自动配置MysqlSingularTable = true
:表名不加sMysqlMaxIdleConns = 20
: 设置空闲连接池中的最大连接数MysqlMaxOpenConns = 100
:设置数据库连接最大打开数MysqlConnMaxLifetime = 30
:设置可重用连接的最长时间
接下来运行main.go
即可。具体的代码参考仓库。